using System;
using System.Collections.Generic;
using System.Text;
using Entity;
using System.Data.SqlClient;
using System.Data;
using ECommerce.DAL;

namespace Entity
{
    [System.ComponentModel.DataObject]
    public class TblExportImportProductExtended : TblExportImportProduct
    {
        public static void TruncateTable()
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EXPORTIMPORTDATA_TRUNCATE_TABLE);
            ExecuteScalarCmd(sqlCmd);
        }

        public static CustomCollection<TblExportImportProduct> GetExportImportProductByIsInserted(bool IsInserted)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@IsInserted", SqlDbType.Bit, 0, ParameterDirection.Input, IsInserted);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EXPORTIMPORTDATA_BY_IS_INSERTED);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblExportImportProductCollectionFromReader);
            CustomCollection<TblExportImportProduct> objCollection = ((CustomCollection<TblExportImportProduct>)ExecuteReaderCmd(sqlCmd, reader));
            return objCollection;
        }

        public static int CountItemNumber(string itemNumber)
        {
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@ItemNumber", SqlDbType.NVarChar, 50, ParameterDirection.Input, itemNumber);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_EXPORTIMPORTDATA_GET_ITEM_NUMBER_COUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        private const string SP_TBL_EXPORTIMPORTDATA_TRUNCATE_TABLE = "sp_TblExportImportProduct_Truncate_Table";
        private const string SP_TBL_EXPORTIMPORTDATA_BY_IS_INSERTED = "sp_TblExportImportProduct_GetTblExportImportProductByIsInserted";
        private const string SP_TBL_EXPORTIMPORTDATA_GET_ITEM_NUMBER_COUNT = "sp_TblExportImportProduct_Get_ItemNumber_Count";
    }
}
